package com.unicom.projt.util;

import java.util.Date;

/**
 * Created by IntelliJ IDEA.
 * User: Lee
 * Date: 11-12-15
 * Time: 下午1:50
 */
public class PostXmlBuilder {
    private class PostXml {
        private String biPCode;
        private String telNo;
        private String userPas;
        private String svcCont;
        private String actionID="001";

        private PostXml() {
        }
    }

    private PostXml postXml;

    public PostXmlBuilder() {
        postXml = new PostXml();
    }

    public PostXmlBuilder setBiPCode(String bipCode) {
        this.postXml.biPCode = bipCode;
        return this;
    }

    public PostXmlBuilder setTelNo(String telNo) {
        this.postXml.telNo = telNo;
        return this;
    }

    public PostXmlBuilder setUserPas(String userPas) {
        this.postXml.userPas = userPas;
        return this;
    }

    public PostXmlBuilder setSvcCont(String svcCont) {
        this.postXml.svcCont = svcCont;
        return this;
    }

    public PostXmlBuilder setActionID(String actionID) {
        this.postXml.actionID = actionID;
        return this;
    }

    public String createXml() {
        StringBuilder sb = new StringBuilder();
        sb.append("<MobilePay>");
        sb.append("<OrigDomain>Mobile</OrigDomain>");
        sb.append("<OS>Android</OS>");
        sb.append("<BIPCode>");
        sb.append(this.postXml.biPCode);
        sb.append("</BIPCode>");
        sb.append("<BIPVer>1</BIPVer>");
        sb.append("<ActionCode>0</ActionCode>");
        sb.append("<UserInfo>");
        sb.append("<TelNo>");
        sb.append(this.postXml.telNo);
        sb.append("</TelNo>");
        if (this.postXml.userPas != null && !"".equals(this.postXml.userPas)) {
            sb.append("<UserPas>");
            sb.append(this.postXml.userPas);
            sb.append("</UserPas>");
        }
        sb.append("</UserInfo>");
        sb.append("<ActionID>");
        sb.append(this.postXml.actionID);
        sb.append("</ActionID>");
        sb.append("<ProcessTime>");
        sb.append(DateUtils.formatOrderDateTime(new Date()));
        sb.append("</ProcessTime>");
        sb.append("<TestFlag>0</TestFlag>");//0非测试，1测试
        if (this.postXml.svcCont != null) {
            sb.append(this.postXml.svcCont);
        }
        sb.append("</MobilePay>");
        return sb.toString();
    }

}
